package codingDudes.utils;

import codingDudes.geom.Point2D;

/**
 * This class provides methods for correction of position and angle according
 * to the hardware setup of the Maeve Multitouch-Table.
 * 
 * @author Tobias Friese
 */

public class MaeveCorrection
{
	private static final double HALF_PI = Math.PI * .5;
	
	/**
	 * Returns a corrected x position.
	 * 
	 * @param x x position
	 * @param y y position
	 * @return corrected x position
	 */
	public static double correctX(double x, double y)
	{
		// return (1 * x) * 0.9945f + 5f + (y * 1f - y) * 1;
		
		return (x * 0.9945d) + 5d;
	}
	
	/**
	 * Returns a corrected y position.
	 * 
	 * @param x x position
	 * @param y y position
	 * @return corrected y position
	 */
	public static double correctY(double x, double y)
	{
		// return (1 * y) * 1.325f - 175.0f + (x * 0.998f - x) * 1;
		
		return (y * 1.325d) - 175d + (x * -0.002d);
	}
	
	/**
	 * Returns a corrected Point2D object.
	 * 
	 * @param x x position
	 * @param y y position
	 * @return corrected Point2D object
	 */
	public static Point2D correctPoint(double x, double y)
	{
		return new Point2D(correctX(x, y), correctY(x, y));
	}
	
	/**
	 * Returns a corrected Point2D object.
	 * 
	 * @param point Point2D object to correct
	 * @return corrected Point2D object
	 */
	public static Point2D correctPoint(Point2D point)
	{
		return new Point2D((correctX(point.x, point.y)), correctY(point.x, point.y));
	}

	/**
	 * Returns a corrected angle.
	 * 
	 * @param angle the angle to correct as radians
	 * @return a corrected angle
	 */
	public static double correctAngle(double angle)
	{
		return (-1 * angle) - HALF_PI;
	}
}
